const app = getApp()

Component({
  properties: {
    goodsList: {
      type: Object,
      value: []
    }
  },
  data: {},
  methods: {
    // 选择
    goodsSub(e) {
      let orderId = e.currentTarget.dataset.orderid
      app.api.goodsGet(orderId)
        .then(res => {
          let goodsSpu = res.data
          if (goodsSpu) {
            let goodsSku = goodsSpu.skus[0]
            let specInfo = ''
            /* 把参数信息异步存储到缓存当中 */
            wx.setStorage({
              key: 'param-orderConfirm',
              data: [{
                spuId: goodsSpu.id,
                skuId: goodsSku.id,
                quantity: 1,
                salesPrice: goodsSku.salesPrice,
                spuName: goodsSpu.name,
                sellPoint: goodsSpu.sellPoint,
                specInfo: specInfo,
                picUrl: goodsSku.picUrl ? goodsSku.picUrl : goodsSpu.picUrls[0],
                pointsDeductSwitch: goodsSpu.pointsDeductSwitch,
                pointsDeductScale: goodsSpu.pointsDeductScale,
                pointsDeductAmount: goodsSpu.pointsDeductAmount,
                pointsGiveSwitch: goodsSpu.pointsGiveSwitch,
                pointsGiveNum: goodsSpu.pointsGiveNum,
                freightTemplat: goodsSpu.freightTemplat,
                weight: goodsSku.weight,
                volume: goodsSku.volume,
                deliveryPlace: goodsSpu.deliveryPlace
              }]
            })
            wx.navigateTo({
              url: '/pages/order/order-confirm/index'
            })
          }
        })
    }
  }
})